package org.apache.jena.query.spatial.pfunction;

import org.apache.jena.query.spatial.DistanceUnitsUtils;
import org.apache.lucene.spatial.query.SpatialOperation;

import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.context.jts.JtsSpatialContext;
import com.spatial4j.core.shape.Shape;

public class SpatialMatch {

	private final Shape shape;
	private final int limit;
	private final SpatialOperation operation;
	private final SpatialContext ctx = JtsSpatialContext.GEO;

	public SpatialMatch(Double latitude, Double longitude, Double radius,
			String units, int limit, SpatialOperation operation) {

		double degrees = DistanceUnitsUtils.dist2Degrees(radius, units);
		this.shape = ctx.makeCircle(longitude, latitude, degrees);
		this.limit = limit;
		this.operation = operation;
	}

	public SpatialMatch(Double latitude1, Double longitude1, Double latitude2,
			Double longitude2, int limit, SpatialOperation operation) {
		this.shape = ctx.makeRectangle(longitude1, longitude2, latitude1, latitude2);
		this.limit = limit;
		this.operation = operation;
	}

	public Shape getShape() {
		return shape;
	}

	public int getLimit() {
		return limit;
	}

	public SpatialOperation getSpatialOperation() {
		return operation;
	}

	public String toString() {
		return "(" + shape + " " + limit + " " + operation + ")";
	}

}
